<?php

if (!defined('BASEPATH'))
	exit('No direct script access allowed');


class service extends CI_Controller {

	function __construct() {
		parent::__construct();
		$this->load->model(array('m_hewan', 'm_pengguna', 'm_penyakit', 'm_diagnosa', 'm_dokter'));
	}


	function index() {
		$this->load->library('xmlrpc');
		$this->load->library('xmlrpcs');
        //select
		$config['functions']['login'] = array('function' => 'service.login');
                $config['functions']['logindokter'] = array('function' => 'service.logindokter');
		$config['functions']['get_penyakit'] = array('function' => 'service.get_penyakit');
		$config['functions']['get_gejala'] = array('function' => 'service.get_gejala' );
                $config['functions']['bobotgejala'] = array('function' => 'service.bobotgejala' );
                $config['functions']['getallpenyakit'] = array('function' => 'service.getallpenyakit' );
                $config['functions']['get_user'] = array('function' => 'service.get_user' );
                 $config['functions']['get_id_pemilik'] = array('function' => 'service.get_id_pemilik' );
                $config['functions']['get_penyakitwhereidgejala'] = array('function' => 'service.get_penyakitwhereidgejala' );
                $config['functions']['tambahpemilik'] = array('function' => 'service.tambahpemilik' );
                  $config['functions']['tambahperiksa'] = array('function' => 'service.tambahperiksa' );
                    $config['functions']['tambahhewan'] = array('function' => 'service.tambahhewan' );
		$this->xmlrpcs->initialize($config);
		$this->xmlrpcs->serve();
	}


	function login($request) {
		$param = $request->output_parameters();
		$data = $this->m_pengguna->login($param[0], $param[1]);
		$response = array(json_encode($data));
		return $this->xmlrpc->send_response($response);
	}
        
        function logindokter($request) {
		$param = $request->output_parameters();
		$data = $this->m_dokter->logindokter($param[0], $param[1]);
		$response = array(json_encode($data));
		return $this->xmlrpc->send_response($response);
	}
        
        

	function get_penyakit(){
		$data = $this->m_penyakit->ambil();
		$response = array(json_encode($data));
		return $this->xmlrpc->send_response($response);
	}


//	function get_gejala($request){
//                $param = $request->output_parameters();
//		$data = $this->m_diagnosa->ambilgejalabyjenis($param[0]);
//		$response = array(json_encode($data));
//		return $this->xmlrpc->send_response($response);
//	}
        
        function get_gejala($request){
                $param = $request->output_parameters();
		$data = $this->m_diagnosa->ambilgejalabyjenis();
		$response = array(json_encode($data));
		return $this->xmlrpc->send_response($response);
	}
        
        function bobotgejala($request){
                $param = $request->output_parameters();
		$data = $this->m_diagnosa->bobotgejala();
		$response = array(json_encode($data));
		return $this->xmlrpc->send_response($response);
	}
        
        function getallpenyakit($request){
                $param = $request->output_parameters();
		$data = $this->m_penyakit->getallpenyakit();
		$response = array(json_encode($data));
		return $this->xmlrpc->send_response($response);
	}
        
        function get_penyakitwhereidgejala($request){
             $param = $request->output_parameters();
             $data = $this->m_penyakit->penyakit_wheregejala($param[0], $param[1]);
             $response = array(json_encode($data));
             return $this->xmlrpc->send_response($response);
        }
        
        function get_user($request){
            $param = $request->output_parameters();
            $data = $this->m_penyakit->get_user($param[0]);
            $response = array(json_encode($data));
            return $this->xmlrpc->send_response($response);
        }
        
        function get_id_pemilik($request){
            $param = $request->output_parameters();
            $data = $this->m_pengguna->get_id_pemilik($param[0]);
            $response = array(json_encode($data));
            return $this->xmlrpc->send_response($response);
        }
                
        
        function tambahpemilik($request) {
        $parameters = $request->output_parameters();

     //   $di['id_pemilik_hewan'] = $parameters[0];
        $di['nama'] = $parameters[0];
        $di['Alamat'] = $parameters[1];
        $di['nomor_hp'] = $parameters[2];
        
        $data =  $this->m_hewan->tambahpemilik($di);
        $response = json_encode($data);
        if($data == true){
            $response = 1;
        } else{
            $response = 0;
        }
        return $this->xmlrpc->send_response($response);
    }
    
    
      function tambahperiksa($request) {
        date_default_timezone_set('Asia/Jakarta');
        $parameters = $request->output_parameters();
         $now = date("Y-m-d H:i:s");
        $di['id_pemilik_hewan'] = $parameters[1];
        $di['id_user'] = $parameters[0];
       // $di['id_hewan'] = $parameters[1];
        $di['tgl_periksa'] = $now;
        $di['Jenis_hewan'] = $parameters[2];
        $di['umur'] = $parameters[3];
        $di['Berat'] = $parameters[4];
        
        $data =  $this->m_hewan->tambahperiksa($di);
        $response = json_encode($data);
        if($data == true){
            $response = 1;
        } else{
            $response = 0;
        }
        return $this->xmlrpc->send_response($response);
    }
    
     function tambahhewan($request) {
        $parameters = $request->output_parameters();
         
     //   $di['id_pemilik_hewan'] = $parameters[0];
        $di['id_pemilik_hewan'] = $parameters[0];
        $di['jenis_hewan'] = $parameters[1];
        $di['umur'] = $parameters[2];
        $di['berat'] = $parameters[1];
        
        $data =  $this->m_hewan->tambahhewan($di);
        $response = json_encode($data);
        if($data == true){
            $response = 1;
        } else{
            $response = 0;
        }
        return $this->xmlrpc->send_response($response);
    }



}



